﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI.WebControls;

namespace NetJsWire.Widgets.Ui.Form
{
    public class ComboBoxColumn
    {
        private object dataSource;
        private string field;
        private string name;
        private ComboBox parent;
        private TextAlign textAlign = TextAlign.Left;
        private int width = 50;

        public ComboBoxColumn( ComboBox parent )
        {
            this.parent = parent;
            dataSource = parent.DataSource;
        }

        public ComboBoxColumn()
        {
            parent = null;
        }

        public ComboBoxColumn( string field )
            : this()
        {
            this.field = field;
        }

        public ComboBoxColumn( string field, string header )
            : this( field )
        {
            this.Header = header;
        }

        public ComboBoxColumn( string field, string header, int width )
            : this( field, header )
        {
            this.width = width;
        }

        public ComboBoxColumn( string field, string header, int width, int left )
            : this( field, header, width )
        {
            this.Left = left;
        }

        public ComboBoxColumn( string field, string header, int width, int left,
                               TextAlign align )
            : this( field, header, width )
        {
            textAlign = align;
        }

        [Editor( "System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            , typeof( UITypeEditor ) ), Description( "The field binded to the column" ), DefaultValue( "" ),
         TypeConverter( "System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             ), Category( "Data" )]
        public string Field
        {
            get { return field; }
            set { field = value; }
        }

        [Browsable( false ), EditorBrowsable( EditorBrowsableState.Never )]
        internal ComboBox Parent
        {
            get { return parent; }
            set
            {
                parent = value;
                dataSource = parent.DataSource;
            }
        }

        [Browsable( false ), EditorBrowsable( EditorBrowsableState.Never )]
        public object DataSource
        {
            get { return dataSource; }
        }

        [DefaultValue( ( string ) null )]
        public string Name
        {
            get
            {
                if ( string.IsNullOrEmpty( name ) )
                    name = "col" + field;
                return name;
            }
            set { name = value; }
        }

        [DefaultValue( ( string ) null )]
        public string Header { get; set; }

        [DefaultValue( 50 )]
        public int Width
        {
            get { return width; }
            set { width = value; }
        }

        [DefaultValue( 0 )]
        public int Left { get; set; }

        [DefaultValue( 1 )]
        public TextAlign TextAlign
        {
            get { return textAlign; }
            set { textAlign = value; }
        }
    }
}